package com.sff.site.node {
	
	
	public class NodeDescriptor {

		
		public function NodeDescriptor( datas : XML ) {
			parse( datas );
		}
		
		/**
		 * return childs (NodeDescriptor) of this node
		 */
		public function getChilds() : Array {
			return _childs;
		}
		
		
		/**
		 * the id / name of the node
		 */
		public function get id() : String {
			return _id;
		}
		
		/**
		 * retrn the default child node to activarte if no one is currently active
		 */
		public function get defaultId() : String {
			return _defaultId;
		}
		
		protected function parse( datas : XML ) : void {
			//validate( datas );
			if( datas == null )
				throw new Error( "NodeDescriptor - parse : " );
			
			_childs = new Array( );
			
			grabId( datas );

			default xml namespace = datas.namespace();
			
			for each ( var nodeData : XML in datas.node )
				_childs.push( new NodeDescriptor( nodeData ) );
		}
		

		protected function validate(datas : XML) : void {
			
		}

		protected function grabId(datas : XML) : void {
			_id = datas.@id.toString();
			if( datas.@default.length() )
				_defaultId = datas.@default.toString();
		}

		protected var _id : String;
		protected var _defaultId : String;
		protected var _childs : Array/*NodeDescriptor*/;
		
	}
}
